%let te = 38;
%let y = %sysfunc(mod(&base_yr,100));



%macro get_nonfilers;

	
	proc printto log = "&logdir/get_nonfilers.txt" new;
	run;
	
	
		data _null_;
			set rlib.nf_universe;
			file "&tmpdir./tinlist" dlm=',';
			put person_id; 
		run;
	
	%let te = 38;
	
	
		/****************************************
		*										*
		*			Start PROC SQL				*
		*										*
		****************************************/
		proc sql noprint;
		[connection details redacted]
				

		create table nonfilers as 
		select * from connection to iq
		(
				/* Find the full set of filers */

				select
					[redacted] as person_id
				into #prim
				from [redacted]
				where [redacted] = &base_yr 
					and mod([redacted],1000) = &te
					and ([redacted] ~= 1 or [redacted] ~= 1 or [redacted] ~= 1 or [redacted] <= 202015)

				select 
					b.[redacted] as person_id
				into #sec
				from [redacted] as a
					inner join [redacted] as b
						on(a.[redacted] = b.[redacted] and a.[redacted] = b.[redacted])
				where a.[redacted] = &base_yr
					and a.[redacted] = 2
					and  (a.[redacted] ~= 1 or a.[redacted] ~= 1 or a.[redacted] ~= 1 or a.[redacted] <= 202015)
					and mod(b.[redacted],1000) = &te


				select distinct
					person_id
				into #tax
				from #prim
				union
				select distinct
					person_id
				from #sec

				select 
					a.person_id
				from #tinlist as a 
					left outer join #tax as b 
						on(a.person_id = b.person_id)
				where b.person_id is null
				order by a.person_id


		);
		disconnect from iq;
		quit;


		/* merge on original variables, other processing */
		proc sort data = rlib.nf_universe;
			by person_id;
		run;

		data nonfilers;
			merge nonfilers(in=a) rlib.nf_universe(in=b);
			by person_id;
			if a & b;
		
			prim_tin = person_id;
			yob_nonfiler = floor(date_of_birth/10000);
			sex_nonfiler = sex;
			
			prim_unmasked_tin = input(ssn,9.);
			
			keep prim_tin prim_unmasked_tin yob_nonfiler sex_nonfiler f1095 info_return;
		run;

		proc freq data = nonfilers;
			tables f1095*info_return;
		run;
		
		/* need to hit against soi file */
		
		proc sort data = rlib.soi;
			by prim_unmasked_tin;
		run;
		proc sort data = nonfilers nodupkey;
			by prim_unmasked_tin;
		run;
		
		data rlib.nonfilers_prefs;
			merge nonfilers(in=a) rlib.soi(keep=prim_unmasked_tin in=b);
			by prim_unmasked_tin;
			if a = 1 & b = 0;
		run;
		
		
		
	
	
	proc printto;
	run;
	
%mend;
